package org.jmh.gift.strategy.impl;

import org.jmh.gift.strategy.IShopCarStrategy;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 按照hash值做分组
 */
public class ShopCarHashStrategy implements IShopCarStrategy {

    private Integer num;

    public ShopCarHashStrategy(){
        this.num = 100;
    }

    public ShopCarHashStrategy(Integer num){
        this.num = num;
    }

    @Override
    public Map<String, List<String>> group(Set<String> keys) {
        return keys.stream()
                .collect(Collectors.groupingBy(x -> (x.hashCode()%this.num)+""));
    }
}
